package middlewares

import (
	"gitee.com/DonHz/electronic-business-systems/mxshop-api/user_web/models"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"net/http"
)

func IsAdminAuth() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		claimsAny, ok := ctx.Get("claims")
		if !ok {
			zap.L().Error("【IsAdminAuth】从上下文获取claims失败")
			return
		}
		claims := claimsAny.(*models.CustomClaims)
		if claims.Role == 1 {
			ctx.JSON(http.StatusForbidden, gin.H{
				"msg": "用户无权限",
			})
			ctx.Abort()
			return
		}
	}
}
